using System;
using System.Collections.Generic;
using LaxCraft.Domain;

namespace LaxCraft.Repositories
{
	using NHibernate;

	using LaxCraft.Plumbing;

	public class PostRepository : IPostRepository
	{
		private readonly ISession session;

		public PostRepository(ISession session)
		{
			this.session = session;
		}

	    public IEnumerable<Post> GetPosts()
	    {
            using (var tx = session.BeginTransaction()) {
                var data = session.QueryOver<Post>().Future();
                tx.Commit();
                return data;
            }
	    }

	    public void Save(Post post)
	    {
            using (var txn = session.BeginTransaction())
            {
                session.Save(post);
                txn.Commit();
            }
	    }
	}
}